import ElementPlus from 'element-plus';
import zhCn from 'element-plus/es/locale/lang/zh-cn';
import { commonUtils } from 'my-ts-core';
import { createPinia } from 'pinia';
import { createApp, defineAsyncComponent } from 'vue';

import router from '@/app-router';

import '@/style.css';
import 'element-plus/dist/index.css';

const App = defineAsyncComponent(() => import('@/App.vue'));

// This is for sockjs-client usage.
(window as any).global = window;

const pinia = createPinia();
const app = createApp(App);
app.use(pinia);
app.use(router);

app.use(ElementPlus, {
  locale: zhCn,
});

// app-level error handler that captures errors from all descendent components.
if (!commonUtils.isDevEnv) {
  app.config.errorHandler = (err) => {
    console.error(`General error occured: ${err}`);
  };
}

app.mount('#app');
